{extend name="admin/b2c/base" /}
{block name="resources"/}
<link href="ADMIN_CSS/express/transportation_edit.css" rel="stylesheet"/>
{/block}
{block name="main"}
<input type="hidden" id="shipping_fee_id" value="{$shipping_fee_id}"/>
<div class="mod-form t20" style="margin-top: 40px;">
	<div class="con style0page">
		<ul class="list-ul">
			<li class="list-li">
				<div class='table-div'>
					<table>
						<tr>
							<td colspan='2' class='back-f5f5f5'>
								<div class='table-title-font'><span>运费信息</span></div>
							</td>
						</tr>
						<tr>
							<td class='table-1td'>
								<li class="list-li">
									<div class="float-l w130">
										<span class="star">*</span>
										<label>模板名称:</label>
									</div>
								</li>
							</td>
							<td>
								<li class="list-li">
									<div class="float-l">
										<input id="TextName" type="text" name="TextName" style="width:220px;margin:0px;" class="w230" value="{$shipping_fee_name}">
									</div>
									<div class="float-l">
										<span class="prompt"></span>
									</div>
								</li>
							</td>
						</tr>
						<tr>
							<td class='table-1td'>
								<li class="list-li">
									<div class="float-l w130">
										<span class="star">*</span>
										<label>运费:</label>
									</div>
								</li>
							</td>
							<td>
								<li class="list-li">
									<div class="float-l" id="fee_box">
										{foreach name="order_shipping_fee_info[1]" item="info" key="k"}
										{if condition="$info.is_default eq 1"}
										<div id="PressPaper" style="border:1px solid #e6e6e6;width:713px;padding:10px;">
											<span>默认运费：{$info.is_default}</span>
											<input type="text" id="NumberStartStandard" name="StartStandard0" value="{$info.snum}" class="w100">
											<span id="defaultUnit">件</span>
											<span class="l15">费用：</span>
											<input type="text" id="NumberStartFee" name="StartFee0" class="w100"value="{$info.sprice}">
											<span id="defaultMoney">元</span>
											
											<span class="l15">每增加：</span>
											<input type="text" id="NumberAddStandard" value="{$info.xnum}"name="StartAddStandard0" class="w100">
											<span id="defaultAddUnit">件</span>
											<span class="l15">费用增加：</span>
											<input type="text" id="NumberAddFee" name="StartAddFee0" class="w100"value="{$info.xprice}">
											<span id="defaultAddMoney">元</span>
					
											<a class="l15"style="float:right; height: 32px;line-height: 32px;" onclick="deleteThisParentBox(this);">删除</a>
										</div>
										{/if}
										{/foreach}
										<div class="mod-table-main t10">
											<div class="con style03" id="tbl-except">
												<table style="width: 735px;" id="myPressPaperTable">
													<colgroup>
														<col style="width: 34%;">
														<col style="width: 15%;">
														<col style="width: 15%;">
														<col style="width: 15%;">
														<col style="width: 15%;">
														<col style="width: 6%;">
													</colgroup>
													<tbody>
														<tr>
															<td class="td_bg">运送到</td>
															<td class="td_bg"><span id="initialWorkpiece">首件(件)</span></td>
															<td class="td_bg"><span id="collectFees">首费(元)</span></td>
															<td class="td_bg"><span id="Continued">续件(件)</span></td>
															<td class="td_bg" ><span id="Renew">续费(元)</span></td>
															<td class="td_bg">操作</td>
														</tr>
														{foreach name="order_shipping_fee_info[0]" item="info" key="k"}
														{if condition="$info.is_default eq 0"}
														<tr id="trRow{$k+1}">
															<td>
																<div>{$info.address_name}</div> 
																<div class="mod-operate float-r">
																	<div class="con style0editdel" style="float:right;">
																		<a id="edit{$k+1}" onclick="openBg(1,event);openSelect(1);" title="编辑运送区域" class="del" href="javascript:void(0)">编辑</a>
																	</div>
																</div>
																<input type="hidden" name="furniture_areas_n{$k+1}" value="{$info.address_id}">
																<input type="hidden" name="furniture_areas_name_n{$k+1}" value="{$info.province_id};{$info.city_id}">
															</td>
															<td><input id='StartStandard_{$k+1}' class='w30' type='text' value='{$info.snum}' name='StartStandard{$k+1}' /></td>
															<td><input id='StartFee_{$k+1}' class='w30' type='text' name='StartFee{$k+1}' value="{$info.sprice}"/></td>
															<td><input id='StartAddStandard_{$k+1}' class='w30' type='text'  value="{$info.xnum}" name='StartAddStandard{$k+1}' /></td>
															<td><input id='StartAddFee_{$k+1}' class='w30' type='text' name='StartAddFee{$k+1}' value="{$info.xprice}"/></td>
															<td>
																<div class='mod-operate'>
																	<div class='con style0editdel'>
																		<a name='de_{$k+1}' class='del' href='javascript:void(0)' onclick="dlRow('trRow{$k+1}')">删除</a>
																	</div>
																</div>
															</td>
														</tr>
														{/if}
														{/foreach}
													</tbody>
												</table>
											</div>
										</div>
										<div class="t10" style="margin:10px 0;">
											<a class="btn-gradient-blue" id="J_AddRule" onclick="InsertRow()" href="javascript:void(0)">为指定地区城市设置运费</a>
										</div>
									</div>
									<div class="float-l" style="margin-left:6px;">
										<span class="prompt" id="spMessage"></span>
									</div>
								</li>
							</td>
						</tr>
					</table>
				</div>
			</li>
		</ul>
		<div class="l130 t20 b20" style="margin-bottom:10px;margin-top:30px;text-align:center;">
			<button type="button" onclick="javascript:TransportationEdit();" class="edit_button">保存</button>
		</div>
	</div>
	<div class="fill" style="height:280px;display:none;"></div>
</div>
<div id="bg"></div>
<div id="selectItem" style="display:none;top:320px;">
	<div class="tit bgc_ccc move">
		<h2 class="left" style="margin:-10px 0;">请选择城市</h2>
		<span class="pointer right" onclick="openBg(0,event);openSelect(0);">[取消]</span>
		<span class="pointer right" onclick="makeSure();">[确定]</span>
		<input type="hidden" id="hidMakeSure">
		<input type="hidden" id="hidArea">
		<input type="hidden" id="hidAreaName">
	</div>
	<div class="cls"></div>
	<div class="cont">
		<div class="selectSub dialog-areas">
			<ul id="J_CityList">
				{foreach name="address_list" item="area" key="k"}
				<li>
					<div class=" dcity clearfix">
						<div class="ecity gcity">
							<span class="group-label">
								<input id="J_Group_{$k}" name="J_Group_{$k}" class="J_Group" type="checkbox" value="{foreach name="area.province_list" item="province"}{$province.province_id},{/foreach}">
								<label for="J_Group_{$k}" style="font-weight:100;">{$area.area_name}</label>
							</span>
						</div>
						<div class="province-list">
							{foreach name="area.province_list" item="province" key="i" }
							<div class="ecity">
								<span class="gareas">
									<input name="J_Group_{$k}_Province"id="J_Province_{$province.province_id}" class="J_Province"type="checkbox" lang="{$province.province_name}"value="{$province.province_id}">
									<label for="J_Province_{$province.province_id}" style="font-weight:100;">{$province.province_name}</label>
									<span class="check_num"></span>
									<img class="trigger" src="ADMIN_IMG/T1XZCWXd8iXXXXXXXX-8-8.gif">
								</span>
								<div class="citys" id="citys_{$province.province_id}">
									{foreach name="province.city_list" item="city" key="i" }
									<span class="areas" style="font-weight:100">
										<input lang="{$city.city_name}" value="{$city.city_id}" id="J_City_100{$city.city_id}" data-value_id="{$city.province_id}:100{$city.city_id}" name="J_City_100{$city.city_id}" class="J_City" type="checkbox">
										<label for="J_City_100{$city.city_id}" style="font-weight:100;">{$city.city_name}</label>
									</span>
									{/foreach}
									<p style="text-align:right;"><input class="close_button" type="button" value="关闭"></p>
								</div>
							</div>
							{/foreach}
						</div>
					</div>
				</li>
				{/foreach}
			</ul>
		</div>
	</div>
</div>
{include file="admin/b2c/openDialog" /}
<script src="ADMIN_JS/express/transportation_add.js"></script>
<script type="text/javascript">
//添加行
function InsertRow(){
	var tableRow = document.getElementById("myPressPaperTable");
	var row_index = tableRow.rows.length;
	var trRow = tableRow.insertRow(row_index);
	trRow.id = "trRow" + row_index;
	var cel1 = trRow.insertCell(0);
	cel1.innerHTML = '<div> 未添加地区</div> <div class="mod-operate float-r"><div class="con style0editdel" style="float:right;"> <a  id="edit' + row_index + '"  onclick="openBg(1,event);openSelect(1);" title="编辑运送区域" class="del" href="javascript:void(0)">编辑</a></div></div><input type="hidden" name="furniture_areas_n' + row_index + '"><input type="hidden" name="furniture_areas_name_n' + row_index + '">';
	var cel2 = trRow.insertCell(1);
	cel2.innerHTML = "<input id='StartStandard_" + row_index + "' class='w30' type='text' value='1' name='StartStandard" + row_index + "' />";
	var cel3 = trRow.insertCell(2);
	cel3.innerHTML = "<input id='StartFee_" + row_index + "' class='w30' type='text' name='StartFee" + row_index + "'/>";
	var cel4 = trRow.insertCell(3);
	cel4.innerHTML = "<input id='StartAddStandard_" + row_index + "' class='w30' type='text' value='1' name='StartAddStandard" + row_index + "' />";
	var cel5 = trRow.insertCell(4);
	cel5.innerHTML = "<input id='StartAddFee_" + row_index + "' class='w30' type='text' name='StartAddFee" + row_index + "'/>";
	var cel6 = trRow.insertCell(5);
	cel6.innerHTML = "<div class='mod-operate'><div class='con style0editdel'><a name='de_" + row_index + "'  class='del' href='javascript:void(0)'  onclick=\"dlRow('trRow" + row_index + "')\"> 删除</a></div> </div>";
	var Rowsindex = 0;
	$(function(){
		$('#tablerow').val(row_index);
	})
	$("#myPressPaperTable tr").not("tr:eq(0)").each(function () {
		Rowsindex++;
		ISinputString("#StartStandard_" + Rowsindex + "");
		ISinputString("#StartFee_" + Rowsindex + "");
		ISinputString("#StartAddStandard_" + Rowsindex + "");
		ISinputString("#StartAddFee_" + Rowsindex + "");
	});
}

$(function () {
	if($("#PressPaper").html() == undefined){
		$("#fee_box").prepend("<a onclick='addDefaultBox(this);'>添加默认模板</a>");
	}
	ISinputString("#NumberStartFee");
	ISinputString("#NumberAddFee");
	onlyNum("#NumberStartStandard");
	onlyNum("#NumberAddStandard");
	ISinputString("#InsuranceFee");
	ISinputString("#InsuranceRate");
});

var flag = false;//防止重复提交
function TransportationEdit() {
	var shipping_fee_name = $("#TextName").val();
	if ($("#TextName").val() == "") {
		$(".prompt", $("#TextName").parent().parent()).text("请输入运费模板");
		$("#TextName").focus();
		return false;
	}
	var shipping_fee_ext = "";
	if($("#PressPaper").html() != undefined){
		if ($("#NumberStartStandard").val() == "") {
			$(".prompt").text("");
			$("#spMessage").text("请输入默认运费");
			$("#NumberStartStandard").focus();
			return false;
		} else if (isNaN($("#NumberStartStandard").val())) {
			$(".prompt").text("");
			$("#spMessage").text("请输入数字类型");
			$("#NumberStartStandard").focus();
			return false;
		} else if ($("#NumberStartFee").val() == "") {
			$(".prompt").text("");
			$("#spMessage").text("请输入费用");
			$("#NumberStartFee").focus();
			return false;
		} else if (isNaN($("#NumberStartFee").val())) {
			$(".prompt").text("");
			$("#spMessage").text("请输入数字类型");
			$("#NumberStartFee").focus();
			return false;
		} else if ($("#NumberAddStandard").val() == "") {
			$(".prompt").text("");
			$("#spMessage").text("请输入续件数");
			$("#NumberAddStandard").focus();
			return false;
		} else if (isNaN($("#NumberAddStandard").val())) {
			$(".prompt").text("");
			$("#spMessage").text("请输入数字类型");
			$("#NumberAddStandard").focus();
			return false;
		} else if ($("#NumberAddFee").val() == "") {
			$(".prompt").text("");
			$("#spMessage").text("请输入续费");
			$("#NumberAddFee").focus();
			return false;
		} else if (isNaN($("#NumberAddFee").val())) {
			$(".prompt").text("");
			$("#spMessage").text("请输入数字类型");
			$("#NumberAddFee").focus();
			return false;
		}
		var shipping_fee_ext=$.trim(""+";"+""+";"+$("#NumberStartStandard").val()+";"+$("#NumberStartFee").val()+";"+
		$("#NumberAddStandard").val()+";"+$("#NumberAddFee").val()+";1|");
	}
	if ($("#tbl-except").css("display") == "block") {
		var Rowsindex = 0;
		var IsNull = true;
		$("#myPressPaperTable tr").not("tr:eq(0)").each(function () {
			Rowsindex++;
			if ($("[name='furniture_areas_n" + Rowsindex + "']").val() == "") {
				$(".prompt").text("");
				$("#tbl-except p .spMessage").text("请选择地区");
				IsNull = false;
			} else if ($("[name='StartStandard" + Rowsindex + "']").val() == "") {
				$(".prompt").text("");
				$("#tbl-except p .spMessage").text("请输入文本");
				$("[name='StartStandard" + Rowsindex + "']").focus();
				IsNull = false;
			} else if (isNaN($("[name='StartStandard" + Rowsindex + "']").val())) {
				$(".prompt").text("");
				$("#tbl-except p .spMessage").text("请输入数字类型");
				$("[name='StartStandard" + Rowsindex + "']").focus();
				IsNull = false;
			} else if ($("[name='StartFee" + Rowsindex + "']").val() == "") {
				$(".prompt").text("");
				$("#tbl-except p .spMessage").text("请输入文本");
				$("[name='StartFee" + Rowsindex + "']").focus();
				IsNull = false;
			} else if (isNaN($("[name='StartFee" + Rowsindex + "']").val())) {
				$(".prompt").text("");
				$("#tbl-except p .spMessage").text("请输入数字类型");
				$("[name='StartFee" + Rowsindex + "']").focus();
				IsNull = false;
			} else if ($("[name='StartAddStandard" + Rowsindex + "']").val() == "") {
				$(".prompt").text("");
				$("#tbl-except p .spMessage").text("请输入文本");
				$("[name='StartAddStandard" + Rowsindex + "']").focus();
				IsNull = false;
			} else if (isNaN($("[name='StartAddStandard" + Rowsindex + "']").val())) {
				$(".prompt").text("");
				$("#tbl-except p .spMessage").text("请输入数字类型");
				$("[name='StartAddStandard" + Rowsindex + "']").focus();
				IsNull = false;
			} else if ($("[name='StartAddFee" + Rowsindex + "']").val() == "") {
				$(".prompt").text("");
				$("#tbl-except p .spMessage").text("请输入文本");
				$("[name='StartAddFee" + Rowsindex + "']").focus();
				IsNull = false;
			} else if (isNaN($("[name='StartAddFee" + Rowsindex + "']").val())) {
				$(".prompt").text("");
				$("#tbl-except p .spMessage").text("请输入数字类型");
				$("[name='StartAddFee" + Rowsindex + "']").focus();
				IsNull = false;
			}
		});
		var num=0;
		if (IsNull) {
			$("#myPressPaperTable tr").not("tr:eq(0)").each(function () {
				num ++;
				shipping_fee_ext +=$.trim($("[name='furniture_areas_name_n" + num + "']").val()+";"
				+$("[name='StartStandard" + num + "']").val()+";"+$("[name='StartFee" + num + "']").val()
				+";"+$("[name='StartAddStandard" + num + "']").val()+";"+$("[name='StartAddFee" + num + "']").val()+";0|");
			})
		}else { return false; }
	}
	if(shipping_fee_ext == ''){
		return false;
	}
	shipping_fee_ext= shipping_fee_ext.substring(0, shipping_fee_ext.length - 1)
	var shipping_fee_id = $("#shipping_fee_id").val();
	if(flag){
		return false;
	}
	flag = true;
	$.ajax({
		type : "post",
		url : "ADMIN_MAIN/Express/TransportationEdit",
		async : true,
		data : {
			"shipping_fee_name" : shipping_fee_name,
			"shipping_fee_ext" : shipping_fee_ext,
			"shipping_fee_id" : shipping_fee_id
		},
		success : function(data) { 
			if (data["code"] > 0) {
				showMessage('success', "运费模板修改成功",'ADMIN_MAIN/Express/Transportation');
			}else{
				showMessage('error', "运费模板修改失败");
				flag = false;
			}
		}
	})
}
</script>
{/block}